﻿#include "RecvMsgEmit.h"

#include <QMutexLocker>

extern QUEUE_DATA<MESG> g_recvQueue;

RecvMsgEmit::RecvMsgEmit(QObject *parent) :
    QThread(parent),
    m_isRun(false)
{
}

void RecvMsgEmit::stopRecvSolveThread()
{
    QMutexLocker locker(&m_mutex);
    m_isRun = false;
}

void RecvMsgEmit::run()
{
    LOG << "test 1";
    m_isRun = true;
    while(true) {
        {
            QMutexLocker locker(&m_mutex);
            if (!m_isRun) {
                return;
            }
        }

       auto msg = g_recvQueue.pop_msg();
       if (nullptr == msg) continue;
       LOG << "forward msg";
       emit recvMsg(msg);
    }

}
